
##### Associated array to store all sum values, as well as, other variables
#set -a KeysOfArray
#set -a ValsOfArray

KeysOfArray=()
ValsOfArray=()

addElement()
{
#key -- $1
#val -- $2
local ind;
ind=`echo ${#KeysOfArray[*]} + 1 |bc`;
KeysOfArray[$ind]=$1;
ValsOfArray[$ind]=$2;
}

findElement()
{
#key -- $1
local ind;
local found;
found=0;
for (( x=1; x<=${#KeysOfArray[@]};x++ ))
do
	ind=`expr match  "${KeysOfArray[$x]}"  ".*${1}.*" `
	if [ -n "$ind"  -a $ind -gt 0 ]
	then
		echo ${ValsOfArray[$x]};
		found=1;
	fi
done
if [ $found -gt 0 ]
 then
	return 0;
else
	return 1;
fi
}

changeElement()
{
#key -- $1
#new value -- $2
local ind;
local found;
found=0;
for (( x=1; x<=${#KeysOfArray[@]};x++ ))
do
        ind=`expr match  "${KeysOfArray[$x]}"  ".*${1}.*" `
        if [ -n "$ind"  -a $ind -gt 0 ]
        then
                ValsOfArray[$x]=$2;
                found=1;
        fi
done
if [ $found -gt 0 ]
 then
        return 0;
else
        return 1;
fi
}



removeElement()
{
#key -- $1
local ind;
local found;
found=0;
for (( x=1; x<=${#KeysOfArray[@]};x++ ))
do
     ind=`expr match  "${KeysOfArray[$x]}"  ".*${1}.*" `
        if [ -n "$ind" -a  $ind -gt 0  ]
        then
                unset $ValsOfArray[$x];
		unset $KeysOfArray[$x]; 
		found=1;
        fi
done
if [ $found -gt 0 ]
 then
        return 0;
else
        return 1;
fi


}


removeAllElement()
{
unset KeysOfArray;
unset ValsOfArray;
return;
}

###########Test
#addElement "jst_pass" "100"
#addElement "jet_pass" "1000"
#addElement "muon_pass" "10"
#findElement "jst"
#findElement "jet"
#set -a pass;
#pass=`findElement "pass" | xargs -I {} echo {} aa`;
#
#pass=(`findElement "pass"`);
#echo "${pass[*]}"
#
#findElement "jst"
#removeElement "jst"
#findElement "jst"
#exit 0;
########End associated array


